Remove the ISO8859-1 restriction from the description of png tEXt
authorMatthias Clasen <matthiasc@src.gnome.org>
Wed, 24 Apr 2002 00:09:29 +0000 (00:09 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Wed, 24 Apr 2002 00:09:29 +0000 (00:09 +0000)
* gdk-pixbuf-io.c (gdk_pixbuf_save): Remove the ISO8859-1
restriction from the description of png tEXt parameters.

* io-png.c (png_text_to_pixbuf_option):
(gdk_pixbuf__png_image_save): If libpng supports it,
store and retrieve non-ISO8859-1 text as UTF-8.  (#76172)

gdk-pixbuf/ChangeLog
gdk-pixbuf/gdk-pixbuf-io.c
gdk-pixbuf/io-png.c

index 787589267a0c07ca229a7a8e444cd41d6dfa9810..ecfcb8aa4ef96cd99e986eabb13565884b771ac2 100644 (file)
@@ -1,3 +1,12 @@
+2002-04-24  Matthias Clasen  <maclas@gmx.de>
+
+       * gdk-pixbuf-io.c (gdk_pixbuf_save): Remove the ISO8859-1
+       restriction from the description of png tEXt parameters.
+
+       * io-png.c (png_text_to_pixbuf_option): 
+       (gdk_pixbuf__png_image_save): If libpng supports it,
+       store and retrieve non-ISO8859-1 text as UTF-8.  (#76172)
+
 2002-04-11  Matthias Clasen  <maclas@gmx.de>
 
        More fixes for #77807:
index 597d4ddabccc79d319cafaa6b4b8d8d2ab740ca8..9b352d089f01a3687e4c40a7f86a5d0f74253cea 100644 (file)
@@ -784,9 +784,7 @@ gdk_pixbuf_real_save (GdkPixbuf     *pixbuf,
  * "quality" parameter; its value should be in the range [0,100]. 
  * Text chunks can be attached to PNG images by specifying parameters of
  * the form "tEXt::key", where key is an ASCII string of length 1-79.
- * The values are UTF-8 encoded strings. Note however that PNG text
- * chunks are stored in ISO-8859-1 encoding, so you can only set texts
- * that can be represented in this encoding.
+ * The values are UTF-8 encoded strings. 
  *
  * Return value: whether an error was set
  **/
index ca1bd17a5ed789afc583b4be3d5fc5181f53c51c..9081096e7dfa6c01bac42f477f3545cc43f2fdf2 100644 (file)
@@ -204,14 +204,19 @@ png_text_to_pixbuf_option (png_text   text_ptr,
                            gchar    **key,
                            gchar    **value)
 {
-        *value = g_convert (text_ptr.text, -1, 
-                            "UTF-8", "ISO-8859-1", 
-                            NULL, NULL, NULL);
+        if (text_ptr.text_length > 0) {
+                *value = g_convert (text_ptr.text, -1, 
+                                    "UTF-8", "ISO-8859-1", 
+                                    NULL, NULL, NULL);
+        }
+        else {
+                *value = g_strdup (text_ptr.text);
+        }
         if (*value) {
                 *key = g_strconcat ("tEXt::", text_ptr.key, NULL);
                 return TRUE;
         } else {
-                g_warning ("Couldn't convert tEXt chunk value to UTF-8.");
+                g_warning ("Couldn't convert text chunk value to UTF-8.");
                 *key = NULL;
                 return FALSE;
         }
@@ -602,7 +607,7 @@ png_info_callback   (png_structp png_read_ptr,
                 return;
         }
 
-        /* Extract tEXt chunks and attach them as pixbuf options */
+        /* Extract text chunks and attach them as pixbuf options */
         
         if (png_get_text (png_read_ptr, png_info_ptr, &png_text_ptr, &num_texts)) {
                 for (i = 0; i < num_texts; i++) {
@@ -753,8 +758,8 @@ gdk_pixbuf__png_image_save (FILE          *f,
 
                for (kiter = keys; *kiter; kiter++) {
                        if (strncmp (*kiter, "tEXt::", 6) != 0) {
-                                g_warning ("Bad option name '%s' passed to PNG saver", *kiter);
-                                return FALSE;
+                               g_warning ("Bad option name '%s' passed to PNG saver", *kiter);
+                               return FALSE;
                        }
                        key = *kiter + 6;
                        len = strlen (key);
@@ -762,7 +767,7 @@ gdk_pixbuf__png_image_save (FILE          *f,
                                g_set_error (error,
                                             GDK_PIXBUF_ERROR,
                                             GDK_PIXBUF_ERROR_BAD_OPTION,
-                                            _("Keys for PNG tEXt chunks must have at least 1 and at most 79 characters."));
+                                            _("Keys for PNG text chunks must have at least 1 and at most 79 characters."));
                                return FALSE;
                        }
                        for (i = 0; i < len; i++) {
@@ -770,7 +775,7 @@ gdk_pixbuf__png_image_save (FILE          *f,
                                        g_set_error (error,
                                                     GDK_PIXBUF_ERROR,
                                                     GDK_PIXBUF_ERROR_BAD_OPTION,
-                                                    _("Keys for PNG tEXt chunks must be ASCII characters."));
+                                                    _("Keys for PNG text chunks must be ASCII characters."));
                                        return FALSE;
                                }
                        }
@@ -787,11 +792,23 @@ gdk_pixbuf__png_image_save (FILE          *f,
                                                      "ISO-8859-1", "UTF-8", 
                                                      NULL, &text_ptr[i].text_length, 
                                                      NULL);
+
+#ifdef PNG_iTXt_SUPPORTED 
+                       if (!text_ptr[i].text) {
+                               text_ptr[i].compression = PNG_ITXT_COMPRESSION_NONE;
+                               text_ptr[i].text = g_strdup (values[i]);
+                               text_ptr[i].text_length = 0;
+                               text_ptr[i].itxt_length = strlen (text_ptr[i].text);
+                               text_ptr[i].lang = NULL;
+                               text_ptr[i].lang_key = NULL;
+                       }
+#endif
+
                        if (!text_ptr[i].text) {
                                g_set_error (error,
                                             GDK_PIXBUF_ERROR,
                                             GDK_PIXBUF_ERROR_BAD_OPTION,
-                                            _("Value for PNG tEXt chunk can not be converted to ISO-8859-1 encoding."));
+                                            _("Value for PNG text chunk %s can not be converted to ISO-8859-1 encoding."), keys[i] + 6);
                                num_keys = i;
                                for (i = 0; i < num_keys; i++)
                                        g_free (text_ptr[i].text);